import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { CopyCodeRule } from "../../rules/CopyCodeRule";
import { Language } from "../../../../extend/language/Language";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { MapFileUtil } from "../../scene/map/MapFileUtil";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { ImagesConst } from "../../resource/ImagesConst";
import { TilePanel } from "../equipment/TilePanel";
import { TaskListCellRender } from "./TaskListCellRender";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { AIManager } from "../../scene/ai/AIManager";
import { Cache } from "../../cache/Cache";
import { AIType } from "../../scene/ai/AIType";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class FairyLandTaskListPanel
    
    export  class FairyLandTaskListPanel extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            setSize(680, 444);
            this.titleHeight = 25;
            this.fairyLandMapCode = GameDefConfig.instance.getCopyMapByCopyId(CopyCodeRule.Copy129);
            this.title = Language.getString(42601);
            return;
        }

        public updateTaskList(arg1: Array<any>): void
        {
            this.tasklist.dataProvider = new DataProvider(arg1);
            this.tasklist.invalidateList();
            if (arg1.length != 0) 
            {
                this._hintText.visible = false;
            }
            else 
            {
                this._hintText.visible = true;
            }
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            Dispatcher.addEventListener(EventName.ChangeScene, this.sceneChangeHander);
            this.sceneChangeHander(null);
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            Dispatcher.removeEventListener(EventName.ChangeScene, this.sceneChangeHander);
            return;
        }

        /* internal  */sceneChangeHander(arg1: Object /* flash.events.Event */): void
        {
            var loc1=MapFileUtil.mapID;
            var loc2=loc1 == this.fairyLandMapCode;
            if (this.goto != null) 
            {
                this.sendto.enabled = !loc2;
                this.goto.enabled = this.sendto.enabled;
            }
            return;
        }

        public updataTask(): void
        {
            this.tasklist.invalidateList();
            this.tasklist.drawNow();
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this.bg = new Object /* flash.display.Bitmap */();
            ObjCreate.setObjAttri(this.bg, 19, 39, -1, -1, this);
            ObjCreate.createBg(18, 38, 645, 368, this);
            var loc1=Language.getString(42610);
            var loc2=GlobalStyle.textFormat1;
            loc2.leading = 6;
            var loc3=ObjCreate.createTextField(loc1, 29, 46, 618, 54, this, loc2, true);
            var loc7;
            loc3.wordWrap = loc7 = true;
            loc3.multiline = loc7;
            loc3.mouseWheelEnabled = loc7 = false;
            loc3.mouseEnabled = loc7;
            var loc4;
            (loc4 = ObjCreate.createTextField(Language.getString(42620), 115, 111, 32, 17, this, GlobalStyle.textFormat6)).filters = [FilterConst.guidePetCall];
            var loc5;
            (loc5 = ObjCreate.createTextField(Language.getString(42621), 305, 111, 32, 17, this, GlobalStyle.textFormat6)).filters = [FilterConst.guidePetCall];
            var loc6;
            (loc6 = ObjCreate.createTextField(Language.getString(42622), 472, 111, 32, 17, this, GlobalStyle.textFormat6)).filters = [FilterConst.guidePetCall];
            this.createStar(146, 109, 5, 25);
            this.createStar(340, 109, 4, 25);
            this.createStar(507, 109, 2, 25);
            ObjCreate.createTextField(Language.getString(42616), 50, 145, 55, 17, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(42617), 186, 145, 55, 17, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(42618), 409, 145, 55, 17, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(42619), 584, 145, 30, 17, this, GlobalStyle.textFormat6);
            ObjCreate.createBg(20, 166, 636, 1, this, ImagesConst.SplitLine);
            this.tasklist = new TilePanel();
            this.tasklist.setSize(636, 180);
            this.tasklist.rowHeight = 45;
            this.tasklist.columnWidth = 615;
            this.tasklist.setStyle("cellRenderer", TaskListCellRender);
            this.tasklist.x = 20;
            this.tasklist.y = 167;
            this.addChild(this.tasklist);
            this._hintText = ObjCreate.createTextField(Language.getString(42626), 180, 230, 350, 20, this, GlobalStyle.textFormat2);
            this._hintText.visible = false;
            this.goto = ObjCreate.createGButton(Language.getString(85002), 485, 365, 68, 22, this);
            this.sendto = ObjCreate.createGButton(Language.getString(85003), 568, 365, 68, 22, this);
            this.goto.addEventListener(flash.events.MouseEvent.CLICK, this.onGotoNPCHandler);
            this.sendto.addEventListener(flash.events.MouseEvent.CLICK, this.onFlyToNPCHandler);
            ObjCreate.createTextField(Language.getString(42609), 193, 414, 300, 20, this, GlobalStyle.textFormat5, true);
            LoaderHelp.addResCallBack(ResFileConst.WuBianHai, this.resourceLoadedHander);
            return;
        }

        /* internal  */onGotoNPCHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            AIManager.onAutoPathAIControl(Cache.instance.scene.getNearlyNpcByCopyId(CopyCodeRule.Copy129));
            return;
        }

        /* internal  */onFlyToNPCHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            AIManager.onAIControl(Cache.instance.scene.getNearlyNpcByCopyId(CopyCodeRule.Copy129), AIType.AI_Convey);
            return;
        }

        /* internal  */resourceLoadedHander(): void
        {
            this.bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.WBH_bg);
            return;
        }

        /* internal  */createStar(arg1: int, arg2: int, arg3: int, arg4: int): void
        {
            var loc1=0;
            while (loc1 < arg3) 
            {
                ObjCreate.createBitmap(ImagesConst.littleStar_big, arg1 + arg4 * loc1, arg2, this);
                ++loc1;
            }
            return;
        }

        /* internal */ /* var */bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */tasklist: TilePanel;

        /* internal */ /* var */goto: GButton;

        /* internal */ /* var */sendto: GButton;

        /* internal */ /* var */_hintText: Object /* flash.text.TextField */;

        /* internal */ /* var */fairyLandMapCode: int;
    }
